package com.labofjet.bean.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;

/**
 * 验证结果
 * 
 * @author jyzjyz12@163.com
 * 
 */
public class ValidationResult {
    Map<String, String> fieldViolationsMap = new HashMap<String, String>();// 成员域验证失败,key=域的名字,value=message
    List<String> violationsList = new ArrayList<String>();// 对象验证失败

    public Map<String, String> getFieldViolationsMap() {
        return fieldViolationsMap;
    }

    public void setFieldViolationsMap(Map<String, String> fieldViolationsMap) {
        this.fieldViolationsMap = fieldViolationsMap;
    }

    public List<String> getViolationsList() {
        return violationsList;
    }

    public void setViolationsList(List<String> violationsList) {
        this.violationsList = violationsList;
    }

    /**
     * 验证结果是否失败
     * 
     * @return
     */
    public boolean isValidationFail() {
        return !fieldViolationsMap.isEmpty() || !violationsList.isEmpty();
    }

    /**
     * 添加成员域验证失败的信息
     * 
     * @param fieldPath
     * @param message
     * @return
     */
    public String putFieldViolationsInfo(String fieldPath, String message) {
        return fieldViolationsMap.put(fieldPath, message);
    }

    /**
     * 添加对象验证失败的信息
     * 
     * @param message
     * @return
     */
    public boolean addViolationsInfo(String message) {
        return violationsList.add(message);
    }
    
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
